﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SaturniLibrary.Utility
{
    public static class DateTimeExtensions
    {
        public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
        {
            int diff = dt.DayOfWeek - startOfWeek;
            if (diff < 0)
            {
                diff += 7;
            }
            return dt.AddDays(-1 * diff).Date;
        }

        public static DateTime NextDayOfWeek(this DateTime dt, DayOfWeek dayOfWeek)
        {
            int diff = dayOfWeek - dt.DayOfWeek;
            if (diff <= 0)
            {
                diff += 7;
            }
            return dt.AddDays(diff).Date;
        }

        public static bool IsToday(this DateTime dt)
        {
            return DateTime.Today.Equals(dt.Date);
        }

        public static bool IsSameDate(this DateTime dt, DateTime dt2)
        {
            return dt2.Date.Equals(dt.Date);
        }
    }
}
